class Solution {
public:
    int widthOfBinaryTree(TreeNode* root) {
         queue<pair<TreeNode*,unsigned int>> q;
         q.push({root,0});
         unsigned int ret=0;
         while(!q.empty())
         {
            //获取最左节点和最右结点
            auto& front=q.front();
            auto& back=q.back();
            //统计最大值
            ret = max(ret,back.second-front.second + 1);
            int size=q.size();
            while(size--)
            {
                auto cur=q.front();
                 q.pop();
                if(cur.first->left)q.push({cur.first->left,cur.second*2+1});
                if(cur.first->right)q.push({cur.first->right,cur.second*2+2});
            }
         }
        return ret;
    }
};